# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import Union, List
from pydantic import BaseModel, Field
from fastapi import Query


class DocsPromptSearchIn(BaseModel):
    """ 模式搜索参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    name: Union[str, None] = Query(default=None, description="文件名称")


class DocsPromptDetailIn(BaseModel):
    """ 模式详情参数 """
    id: int = Query(..., gt=0, description="ID")


class DocsPromptAddIn(BaseModel):
    """ 模式新增参数 """
    icon: str = Field(..., max_length=250, description="图标")
    name: str = Field(..., max_length=100, description="名称")
    intro: str = Field(..., max_length=200, description="简介")
    sort: int = Field(default=0, ge=0, description="排序")
    is_disable: int = Field(..., ge=0, le=1, description="是否禁用: [0=否, 1=是]")
    prompt_dialogue: str = Field(..., max_length=65535, description="摘要提示词")
    prompt_abstract: str = Field(..., max_length=65535, description="翻译提示词")
    prompt_translate: str = Field(..., max_length=65535, description="对话提示词")
    models_dialogue: str = Field(..., max_length=500, description="提问模型")
    models_abstract: str = Field(..., max_length=500, description="总结模型")
    models_translate: str = Field(..., max_length=500, description="翻译模型")
    config_dialogue: dict = Field(..., max_length=65535, description="对话模型配置")
    config_abstract: dict = Field(..., max_length=65535, description="摘要模型配置")
    config_translate: dict = Field(..., max_length=65535, description="翻译模型配置")

    class Config:
        json_schema_extra = {
            "example": {
                "icon": "https://xx.com/storage/9749cbe7beb.png",
                "name": "通用阅读",
                "intro": "综合各种基础阅读场景，快速总结解答",
                "sort": 0,
                "is_disable": 0,
                "prompt_dialogue": "对话提示词",
                "prompt_abstract": "总结提示吃",
                "prompt_translate": "翻译提示吃",
                "models_dialogue": "zhipu:glm-4-long",
                "models_abstract": "zhipu:glm-4-long",
                "models_translate": "zhipu:glm-4-long",
                "config_dialogue": {
                    "context_num": 3,
                    "temperature": 0.95
                },
                "config_abstract": {
                    "context_num": 3,
                    "temperature": 0.95
                },
                "config_translate": {
                    "context_num": 3,
                    "temperature": 0.95
                }
            }
        }


class DocsPromptEditIn(BaseModel):
    """ 模式编辑参数 """
    id: int = Field(..., description="ID")
    icon: str = Field(..., max_length=250, description="图标")
    name: str = Field(..., max_length=100, description="名称")
    intro: str = Field(..., max_length=200, description="简介")
    sort: int = Field(default=0, ge=0, description="排序")
    is_disable: int = Field(..., ge=0, le=1, description="是否禁用: [0=否, 1=是]")
    prompt_dialogue: str = Field(..., max_length=65535, description="摘要提示词")
    prompt_abstract: str = Field(..., max_length=65535, description="翻译提示词")
    prompt_translate: str = Field(..., max_length=65535, description="对话提示词")
    models_dialogue: str = Field(..., max_length=500, description="提问模型")
    models_abstract: str = Field(..., max_length=500, description="总结模型")
    models_translate: str = Field(..., max_length=500, description="翻译模型")
    config_dialogue: dict = Field(..., max_length=65535, description="对话模型配置")
    config_abstract: dict = Field(..., max_length=65535, description="摘要模型配置")
    config_translate: dict = Field(..., max_length=65535, description="翻译模型配置")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "icon": "https://xx.com/76f9749cbe7beb.png",
                "name": "通用阅读",
                "intro": "综合各种基础阅读场景，快速总结解答",
                "sort": 0,
                "is_disable": 0,
                "prompt_dialogue": "对话提示词",
                "prompt_abstract": "总结提示吃",
                "prompt_translate": "翻译提示吃",
                "models_dialogue": "zhipu:glm-4-long",
                "models_abstract": "zhipu:glm-4-long",
                "models_translate": "zhipu:glm-4-long",
                "config_dialogue": {
                    "context_num": 3,
                    "temperature": 0.95
                },
                "config_abstract": {
                    "context_num": 3,
                    "temperature": 0.95
                },
                "config_translate": {
                    "context_num": 3,
                    "temperature": 0.95
                }
            }
        }


class DocsPromptDeleteIn(BaseModel):
    """ 模式删除参数 """
    id: int = Field(..., gt=0, description="ID")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1
            }
        }


"""--------------- Separator ---------------"""


class DocsPromptListVo(BaseModel):
    id: int = Field(description="ID")
    code: str = Field(description="编号")
    icon: str = Field(description="图标")
    name: str = Field(description="名称")
    intro: str = Field(description="简介")
    sort: int = Field(description="排序")
    is_builtin: int = Field(description="系统内置: [0=否, 1=是]")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")
    create_time: str = Field(description="创建时间")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "code": "23864318",
                "icon": "https://xx.com/static/images/general.png",
                "name": "通用阅读",
                "intro": "综合各种基础阅读场景，快速总结解答",
                "sort": 99,
                "is_builtin": 1,
                "is_disable": 0,
                "create_time": "2024-05-20 13:14:00"
            }
        }


class DocsPromptDetailVo(BaseModel):
    id: int = Field(description="ID")
    code: str = Field(description="编号")
    icon: str = Field(description="图标")
    name: str = Field(description="名称")
    intro: str = Field(description="简介")
    sort: int = Field(description="排序")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")
    prompt_dialogue: str = Field(description="摘要提示词")
    prompt_abstract: str = Field(description="翻译提示词")
    prompt_translate: str = Field(description="对话提示词")
    models_dialogue: str = Field(description="对话模型名称")
    models_abstract: str = Field(description="摘要模型名称")
    models_translate: str = Field(description="翻译模型名称")
    config_dialogue: List[dict] = Field(description="对话模型配置")
    config_abstract: List[dict] = Field(description="摘要模型配置")
    config_translate: List[dict] = Field(description="翻译模型配置")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "code": "23864318",
                "icon": "http://127.0.0.1:8100/static/images/docs_general.png",
                "name": "通用阅读",
                "intro": "综合各种基础阅读场景，快速总结解答",
                "sort": 99,
                "is_disable": 0,
                "prompt_dialogue": "对话提示词",
                "prompt_abstract": "总结提示词",
                "prompt_translate": "翻译提示词",
                "models_dialogue": "zhipu:glm-4-long",
                "models_abstract": "zhipu:glm-4-long",
                "models_translate": "zhipu:glm-4-long",
                "config_dialogue": [
                    {
                        "key": "temperature",
                        "name": "温度属性",
                        "type": "slider",
                        "default": 0.95,
                        "range": [
                            0,
                            1.0
                        ],
                        "step": 0.1,
                        "tips": "采样温度，控制输出的随机性，必须为正数取值范围是：[0.0, 1.0]，默认值为0.95。"
                    }
                ],
                "config_abstract": [
                    {
                        "key": "temperature",
                        "name": "温度属性",
                        "type": "slider",
                        "default": 0.95,
                        "range": [
                            0,
                            1.0
                        ],
                        "step": 0.1,
                        "tips": "采样温度，控制输出的随机性，必须为正数取值范围是：[0.0, 1.0]，默认值为0.95。"
                    }
                ],
                "config_translate": [
                    {
                        "key": "temperature",
                        "name": "温度属性",
                        "type": "slider",
                        "default": 0.95,
                        "range": [
                            0,
                            1.0
                        ],
                        "step": 0.1,
                        "tips": "采样温度，控制输出的随机性，必须为正数取值范围是：[0.0, 1.0]，默认值为0.95。"
                    }
                ]
            }
        }
